<template>
  <div>
    正在跳转中.................
  </div>
</template>
<script type="text/ecmascript-6">
import { setCookie, getCookie, delCookie } from '../utils/util'
import Axios from 'axios'
export default {
  name: 'login',
  data () {
    return {
      //定义loading默认为false
      logining: false,
    }
  },
  //进来时执行
  mounted () {
    this.weibologin()
  },
  // 里面的函数只有调用才会执行
  methods: {
    weibologin () {
      let url = window.location.href
      let index = url.lastIndexOf('code=')
      let code = url.substring(index + 5, url.length)
      let params = new URLSearchParams();
      let stua = false;
      //封装数据
      params.append("code", code);
      Axios.post("http://localhost:9091/user/user/weibologin", params).then(res => {
        console.log(res.data);
        if (res.data.code == 200) {
          console.log(res.data);
          //获取权限列表
          this.$store.commit('setRightList', res.data.rights)
          //获取userid
          this.$store.commit('setUserid', res.data.data.id)
          //获取账号
          this.$store.commit('setAccount', res.data.data.account)
          //获取type_id
          this.$store.commit('setType_id', res.data.data.type_id)
          stua = true;
          this.logining = true
          // 测试通道，不为空直接登录
          setTimeout(() => {
            this.logining = false
            this.$store.commit('login', 'true')
            this.$router.push({ path: '/index' })
          }, 1000)

        }
        else {
          window.location.href = 'http://localhost:8080/'
        }
      })
    },
  }
}
</script>

<style scoped>
</style>
